/**
* Copyright (c) 2012-2013 Nokia Corporation. All rights reserved.
* Nokia and Nokia Connecting People are registered trademarks of Nokia Corporation. 
* Oracle and Java are trademarks or registered trademarks of Oracle and/or its
* affiliates. Other product and company names mentioned herein may be trademarks
* or trade names of their respective owners. 
* See LICENSE.TXT for license information.
*/

package com.nokia.example.paint.touch;

import com.nokia.mid.ui.multipointtouch.MultipointTouch;
import com.nokia.mid.ui.multipointtouch.MultipointTouchListener;

/*
 * Class for implementing MultiTouch support.
 */
class MultiTouchImpl extends MultiTouch implements MultipointTouchListener {

    MultiTouchImpl() {
        // Listen for multi-touch events
        MultipointTouch.getInstance().addMultipointTouchListener(this);
    }

    /**
     * Deliver pointer events to listener
     * @param ids array of pointer ids
     */
    public void pointersChanged(int[] ids) {
        for (int i = 0; i < ids.length; i++) {
            int id = ids[i];
            int x = MultipointTouch.getX(id);
            int y = MultipointTouch.getY(id);
            switch (MultipointTouch.getState(id)) {
                case MultipointTouch.POINTER_PRESSED:
                    touchListener.pointerPressed(x, y, id);
                    break;
                case MultipointTouch.POINTER_DRAGGED:
                    touchListener.pointerDragged(x, y, id);
                    break;
                case MultipointTouch.POINTER_RELEASED:
                    touchListener.pointerReleased(x, y, id);
                    break;
            }
        }
    }

    /**
     * @return Amount of supported touch points 
     */
    protected int getPointers() {
        return MultipointTouch.getMaxPointers();
    }
}
